<?php defined('SYSPATH') or die();?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>思途CMS{$coreVersion}</title>
    {template 'stourtravel/public/public_min_js'}
    {php echo Common::getCss('style.css,base.css,base2.css,base_new.css,logistics.css'); }
    {php echo Common::getScript('template.js'); }

</head>
<body>

<table class="content-tab">
    <tr>
        <td width="119px" class="content-lt-td" valign="top">
            {template 'stourtravel/public/leftnav'}
            <!--右侧内容区-->
        </td>
        <td valign="top" class="content-rt-td" style="overflow-x:hidden;">
            <div class="cfg-header-bar">
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" onclick="window.location.reload()">刷新</a>
                <a href="javascript:;" class="fr btn btn-primary radius mt-6 mr-10" id="additem">添加</a>
            </div>
            <div class="cfg-search-bar">
                <div class="cfg-header-search">
                    <input type="text" id="searchkey" placeholder="模板名称" datadef="模板名称" class="search-text" />
                    <a href="javascript:;" class="search-btn" onclick="searchKeyword()">搜索</a>
                </div>
            </div>
            <div class="logistics-container" id="template_list">

            </div>
        </td>
    </tr>
</table>
<script>

    var page = 1;
    var is_allow = 1;
    localStorage.express_searchkey=''
    $(function () {
        get_data();

        //添加
        $('#additem').click(function () {

            ST.Util.addTab('添加运费模板',SITEURL+'express/plan_edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}',0);
        });
        //修改
        $('#template_list').on('click','.edit-tpl',function () {
            var id = $(this).parent().data('id');
            var name = $(this).parent().data('name');
            ST.Util.addTab('修改运费模板-'+name,SITEURL+'express/plan_edit/{if isset($_GET['menuid'])}menuid/{$_GET['menuid']}/{/if}?templateid='+id,0);

        });
        //删除
        $('#template_list').on('click','.del-tpl',function () {
            var id = $(this).parent().data('id');
            var obj = $(this).parents('.logistics-list-block');
            ST.Util.confirmBox('提示','确定要删除吗',function () {
                $.ajax({
                    type:'post',
                    dataType:'json',
                    data:{id:id,action:'del'},
                    url:SITEURL+'express/ajax_update_template',
                    success:function (data) {
                        if(data.status)
                        {
                            obj.remove();
                        }

                    }
                })
            })

         });
        //克隆
        $('#template_list').on('click','.clone-tpl',function () {
            var id = $(this).parent().data('id');
            var obj = $(this).parents('.logistics-list-block');
            ST.Util.confirmBox('提示','确定要克隆吗',function () {
                $.ajax({
                    type:'post',
                    dataType:'json',
                    data:{id:id,action:'clone'},
                    url:SITEURL+'express/ajax_update_template',
                    success:function (data) {
                        if(data.status)
                        {
                            location.reload();

                        }

                    }
                })
            })
        });
        //加载更多
        $(window).scroll(function(){
            // 当滚动到最底部以上100像素时， 加载新内容
            if ($(window).height() - $(this).scrollTop() - $(this).height()<100){
                get_data();
            }
        });



    });


    //加载更多
    function get_data(keyword) {
        console.log(is_allow)
        console.log(page)
        if(is_allow==0||page==-1)
        {
            return false;
        }
        is_allow = 0;
        $.ajax({
            type:'post',
            dataType:'json',
            data:{page:page,keyword:localStorage.express_searchkey},
            url:SITEURL+'express/ajax_more',
            success:function (data) {
                is_allow = 1;
                page = data.page;
                var html=''
                for(var i=0;i<data.list.length;i++){

                    var a1='';
                    a1= '<a class="btn-link clone-tpl" href="javascript:;">复制模板</a>' +
                    '<a class="btn-link ml-5 edit-tpl" href="javascript:;">修改</a>' +
                    '<a class="btn-link ml-5 del-tpl" href="javascript:;">删除</a>'

                    var a2='';
                    if (data.list[i].type==1){
                        a2='首重(g)'
                    }else if(data.list[i].type==2){
                        a2 = '首件(件)'
                    }else {
                        a2 = '首件(立方米)'
                    }

                    var a3='';
                    if (data.list[i].type==1){
                        a3=' 续重(g)'
                    }else if(data.list[i].type==2){
                        a3 = '续件(件)'
                    }else {
                        a3 = '续件(立方米)'
                    }

                    var a4='';
                    for (var i1=0;i1<data.list[i].planlist.length;i1++){
                        a4+= '            <tr>' +
                            '                <td width="55%" class="text-l">' +
                            '                    <div class="ml-30">'+data.list[i].planlist[i1].city_titlelist+'</div>' +
                            '                </td>' +
                            '                <td width="10%" class="text-r">'+data.list[i].planlist[i1].start_num+'</td>' +
                            '                <td width="10%" class="text-r">'+data.list[i].planlist[i1].start_price+'</td>' +
                            '                <td width="10%" class="text-r">'+data.list[i].planlist[i1].continue_num+'</td>' +
                            '                <td width="15%" class="text-r">' +
                            '                    <div class="mr-20">'+data.list[i].planlist[i1].continue_price+'</div>' +
                            '                </td>' +
                            '            </tr>'
                    }

                    html+='<div class="logistics-list-block">' +
                        '        <table class="table">' +
                        '            <thead>' +
                        '            <tr>' +
                        '                <th width="55%" class="text-l">' +
                        '                    <div class="ml-10 c-666 hd-tit">'+data.list[i].title+'</div>' +
                        '                </th>' +
                        '                <th width="30%" colspan="3" class="text-r c-999">最后编辑时间：'+data.list[i].modtime+'</th>' +
                        '                <th width="15%" colspan="1" class="text-r">' +
                        '                <div class="mr-20" data-id=" '+data.list[i].id+' " data-name=" ' +data.list[i].title+' ">'+
                        a1+
                        '                    </div>' +
                        '                </th>' +
                        '            </tr>' +
                        '            </thead>' +
                        '            <tbody>' +
                        '            <tr>' +
                        '                <td width="55%" class="text-l">' +
                        '                    <div class="ml-30">可配送至</div>' +
                        '                </td>' +
                        '                <td width="10%" class="text-r">' +
                        a2+
                        '                </td>' +
                        '                <td width="10%" class="text-r">运费(元)</td>' +
                        '                <td width="10%" class="text-r">' +
                        a3+
                        '                </td>' +
                        '                <td width="15%" class="text-r">' +
                        '                    <div class="mr-20">续费(元)</div>' +
                        '                </td>' +
                        '            </tr>' +
                        a4+
                        '            </tbody>' +
                        '        </table>' +
                        '    </div>'
                }
                $('#template_list').append(html);
            }
        })
    }

    function searchKeyword() {
        is_allow = 1;
        page=1;
        $('#template_list').html('');
        var keyword = $('#searchkey').val()
        localStorage.express_searchkey = keyword
        get_data(keyword);
    }

</script>

</body>
</html>
